package com.woniu.sharepark.leasesystem.common.controller;

import com.woniu.sharepark.common.JsonResult;
import com.woniu.sharepark.common.pojo.Login;
import com.woniu.sharepark.leasesystem.common.constant.SystemConstant;
import com.woniu.sharepark.leasesystem.common.service.OrderFormService;
import com.woniu.sharepark.util.GetLoginUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author DELL
 * @date 2019/6/14 22:08
 * version v1.0
 */
@RequestMapping("orderForm")
@Controller
public class OrderFormController {

    @Autowired
    private OrderFormService orderFormService;

    @RequestMapping("/findOrderById")
    @ResponseBody
    public JsonResult findOrderById(Integer id){
        Map result = orderFormService.findOrderById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setResult(result);
        return jsonResult;
    }

    @RequestMapping("/findAllOrderForm")
    @ResponseBody
    public List findAllOrderForm(){
        Login login = GetLoginUtil.getLogin();
        SystemConstant.ORDER_STATUS = "完成";
        List list = orderFormService.findAllOrderForm(login.getUserInfo().getuId(),SystemConstant.ORDER_STATUS);
        return list;
    }

    @RequestMapping("/findIngOrderForm")
    @ResponseBody
    public List findIngOrderForm(){
        Login login = GetLoginUtil.getLogin();
        SystemConstant.ORDER_STATUS = "已租";
        List list = orderFormService.findAllOrderForm(login.getUserInfo().getuId(),SystemConstant.ORDER_STATUS);
        System.out.println(list);
        return list;
    }

    @RequestMapping("/payIng")
    @ResponseBody
    public JsonResult payIng(){
        JsonResult jsonResult = orderFormService.payIng();
        return jsonResult;
    }

    @RequestMapping("/countSuccessOrder")
    @ResponseBody
    public Integer countSuccessOrder(){
         Integer count = orderFormService.coountSuccessOrder(GetLoginUtil.getLogin().getUserInfo().getuId());
         return count;
    }

    @ResponseBody
    @RequestMapping("/findall")
    public JsonResult findAllOrder(){
        return orderFormService.findAllOrderToJsonResult();
    }
}
